

using System;
using System.Data;
using System.Text;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

using PuntoMascotasWeb.BackEnd.BE;

namespace PuntoMascotasWeb.BackEnd.DAC
{
  /// <summary>
  /// TableDataGateway para Venta.
  /// </summary>
  /// <Date>2013-05-05T15:02:35</Date>
  /// <Author>Mx23</Author>
  public class VentaDAC
  {
    /// <summary>
    /// Insert
    /// </summary>
    /// <param name="pVentaBE">VentaBE</param>
    /// <returns>void</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static void Insert(VentaBE pVentaBE)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Venta_i");

        /// IdVenta
        wDataBase.AddOutParameter(wCmd, "IdVenta", System.Data.DbType.Int32, 4);
        /// Total
        wDataBase.AddInParameter(wCmd, "Total", System.Data.DbType.Decimal, pVentaBE.Total);
        /// IdCliente
        wDataBase.AddInParameter(wCmd, "IdCliente", System.Data.DbType.Int32, pVentaBE.IdCliente);
        /// IdEmpleado
        wDataBase.AddInParameter(wCmd, "IdEmpleado", System.Data.DbType.Int32, pVentaBE.IdEmpleado);
        /// Fecha
        wDataBase.AddInParameter(wCmd, "Fecha", System.Data.DbType.DateTime, pVentaBE.Fecha);

        wDataBase.ExecuteNonQuery(wCmd);
        pVentaBE.IdVenta = (System.Int32)wDataBase.GetParameterValue(wCmd, "IdVenta");
      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// Update
    /// </summary>
    /// <param name="pVentaBE">VentaBE</param>
    /// <returns>void</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static void Update(VentaBE pVentaBE)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Venta_u");

        /// IdVenta
        wDataBase.AddInParameter(wCmd, "IdVenta", System.Data.DbType.Int32, pVentaBE.IdVenta);
        /// Total
        wDataBase.AddInParameter(wCmd, "Total", System.Data.DbType.Decimal, pVentaBE.Total);
        /// IdCliente
        wDataBase.AddInParameter(wCmd, "IdCliente", System.Data.DbType.Int32, pVentaBE.IdCliente);
        /// IdEmpleado
        wDataBase.AddInParameter(wCmd, "IdEmpleado", System.Data.DbType.Int32, pVentaBE.IdEmpleado);
        /// Fecha
        wDataBase.AddInParameter(wCmd, "Fecha", System.Data.DbType.DateTime, pVentaBE.Fecha);

        wDataBase.ExecuteNonQuery(wCmd);

      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// Delete
    /// </summary>
    /// <param name="pIdVenta">IdVenta</param>
    /// <returns>void</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static void Delete(System.Int32 pIdVenta)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Venta_d");

        /// IdVenta
        wDataBase.AddInParameter(wCmd, "IdVenta", System.Data.DbType.Int32, pIdVenta);

        wDataBase.ExecuteNonQuery(wCmd);

      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// GetAll
    /// </summary>

    /// <returns>DataSet</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static DataSet GetAll()
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Venta_s");


        return wDataBase.ExecuteDataSet(wCmd);
      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// GetByParam
    /// </summary>

    /// <returns>DataSet</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static DataSet GetByParam(VentaBE pVentaBE)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Venta_g");


        /// IdVenta
        wDataBase.AddInParameter(wCmd, "IdVenta", System.Data.DbType.Int32, pVentaBE.IdVenta);
        /// Total
        wDataBase.AddInParameter(wCmd, "Total", System.Data.DbType.Decimal, pVentaBE.Total);
        /// IdCliente
        wDataBase.AddInParameter(wCmd, "IdCliente", System.Data.DbType.Int32, pVentaBE.IdCliente);
        /// IdEmpleado
        wDataBase.AddInParameter(wCmd, "IdEmpleado", System.Data.DbType.Int32, pVentaBE.IdEmpleado);
        /// Fecha
        wDataBase.AddInParameter(wCmd, "Fecha", System.Data.DbType.DateTime, pVentaBE.Fecha);

        return wDataBase.ExecuteDataSet(wCmd);

      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }
  }
}